import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @author SaoE
 * @date 2025/2/25 16:00
 */
public class _17 {
    HashMap<String, String> map = new HashMap<String, String>() {{
        put("2", "abc");
        put("3", "def");
        put("4", "ghi");
        put("5", "jkl");
        put("6", "mno");
        put("7", "pqrs");
        put("8", "tuv");
        put("9", "wxyz");
    }};
    List<String> res = new ArrayList<>();
    public List<String> letterCombinations(String digits) {
        if (digits.length() == 0) {
            return res;
        }
        backtrack(digits, 0, new StringBuilder());
        return res;
    }
    public void backtrack(String digits, int index, StringBuilder sb) {
        if (index == digits.length()) {
            res.add(sb.toString());
            return;
        }
        String s = map.get(digits.charAt(index) + "");
        for (int i = 0; i < s.length(); i++) {
            sb.append(s.charAt(i));
            backtrack(digits, index + 1, sb);
            sb.deleteCharAt(sb.length() -1);
        }
    }
}
